/**
 * Copyright (c) 2016-2019 九点科技 All rights reserved.
 *
 * http://www.9dyun.cn
 *
 * 版权所有，侵权必究！
 */
package com.dian.modules.base.controller;

import java.util.List;
import java.util.Map;

import com.dian.common.controller.AbstractController;
import com.dian.common.validator.group.AddGroup;
import com.dian.common.validator.group.UpdateGroup;
import com.dian.common.validator.ValidatorUtils;

import com.dian.common.annotation.SysLog;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.dian.modules.base.entity.UomEntity;
import com.dian.modules.base.service.UomService;
import com.dian.common.utils.PageUtils;
import com.dian.common.utils.R;

import javax.servlet.http.HttpServletResponse;

/**
 * 计量单位
 *
 * @author xiaolai
 * @email xiaolai@9dyun.cn
 * @date 2019-05-14 17:52:50
 */
@RestController
@RequestMapping("base/uom")
public class UomController extends AbstractController {
    @Autowired
    private UomService baseUomService;

    /**
     * 计量单位列表
     */
    @SysLog("计量单位列表")
    @RequestMapping("/list")
    @RequiresPermissions("base:uom:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = baseUomService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 计量单位信息
     */
    @SysLog("计量单位信息")
    @RequestMapping("/info/{id}")
    @RequiresPermissions("base:uom:info")
    public R info(@PathVariable("id") Long id){
		UomEntity baseUom = baseUomService.getById(id);

        return R.ok().put("uom", baseUom);
    }

    /**
     * 计量单位保存
     */
    @SysLog("计量单位保存")
    @RequestMapping("/save")
    @RequiresPermissions("base:uom:save")
    public R save(@RequestBody UomEntity baseUom){
       logger.debug("",baseUom.getPId());

        //数据校验
        ValidatorUtils.validateEntity(baseUom, AddGroup.class);

		baseUomService.save(baseUom);

        return R.ok();
    }

    /**
     * 计量单位修改
     */
    @SysLog("计量单位修改")
    @RequestMapping("/update")
    @RequiresPermissions("base:uom:update")
    public R update(@RequestBody UomEntity baseUom){
        //数据校验
        ValidatorUtils.validateEntity(baseUom, UpdateGroup.class);

		baseUomService.updateById(baseUom);

        return R.ok();
    }

    /**
     * 计量单位删除
     */
    @SysLog("计量单位删除")
    @RequestMapping(value="/delete/{id}",method = RequestMethod.GET)
    @RequiresPermissions("base:uom:delete")
    public R delete(@PathVariable("id") Long id){
		baseUomService.deleteInfo(id);
        return R.ok();
    }
    /**
     * 计量单位树状
     * @param
     * @throws Exception
     */
    @SysLog("计量单位树状")
    @RequiresPermissions("base:uom:list")
    @RequestMapping(value = "/tree", method = RequestMethod.POST)
    public R tree(@RequestParam Map<String, Object> params)  {
        return R.ok().put( baseUomService.queryTreeAll(params));
    }
    /**
     * 计量单位excel导出
     * @param response
     * @throws Exception
     */
    @SysLog("计量单位删除")
    @RequiresPermissions("base:uom:excel")
    @RequestMapping(value = "/excel", method = RequestMethod.GET)
    public void excel(@RequestParam Map<String, Object> params,HttpServletResponse response) throws Exception {
        List<UomEntity> list = baseUomService.queryAll(params);
        //this.exportExcel(response,list);
    }

}
